package worldinruin.gui.imp.gameview;
import java.awt.Dimension;

import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

import worldinruin.GameDataHandler;
import worldinruin.core.ISoldier;
import worldinruin.utils.ResizableLabel;

import com.cloudgarden.layout.AnchorConstraint;
import com.cloudgarden.layout.AnchorLayout;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class SoldierPanel extends javax.swing.JPanel {
	private SpinnerNumberModel jSpinnerModel;
	private JSpinner unitAmountSpinner;
	private JLabel unitIconLabel;
	private ISoldier soldier;
	
	/**
	 * Creates a soldier panel that display soldiers.
	 * @param soldier Soldier type.
	 */
	public SoldierPanel(ISoldier soldier) {
		super();
		this.soldier = soldier;
		initGUI();
		setupGUI();
		
	}
	
	/**
	 * Gets the unit amount of the soldier type.
	 * @return An int of unit amount.
	 */
	public int getAmount() {
		Integer value = (Integer) unitAmountSpinner.getModel().getValue();
		jSpinnerModel.setValue(0);
		return value;
		
	}

	/**
	 * Setup the GUI for the soldier type.
	 */
	private void setupGUI() {
		unitIconLabel = new ResizableLabel(GameDataHandler.getInstance().getIconMap().getIcon(soldier.getSoldierType()).getImage());
		this.add(unitIconLabel, new AnchorConstraint(115, 383, 861, 88, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
		unitIconLabel.setPreferredSize(new java.awt.Dimension(118, 132));
	}
	
	/**
	 * Initializes the GUI.
	 */
	private void initGUI() {
		try {
			AnchorLayout thisLayout = new AnchorLayout();
			this.setLayout(thisLayout);
			setPreferredSize(new Dimension(400, 300));
			{
				jSpinnerModel = 
					new SpinnerNumberModel(0, 0, 1000, 1);
				unitAmountSpinner = new JSpinner();
				this.add(unitAmountSpinner, new AnchorConstraint(327, 864, 715, 604, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
				unitAmountSpinner.setModel(jSpinnerModel);
				unitAmountSpinner.setPreferredSize(new java.awt.Dimension(45, 36));
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
